#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
int romanToInt(char* s)
{
	int res = 0;
	int len = strlen(s);
	while (len)
	{
		char c = *(s+len-1);
		switch (c)
		{
		case 'I':
			res += (res >= 5 ? -1 : 1);
			break;
		case 'V':
			res += 5;
			break;
		case 'X':
			res += 10 * (res >= 50 ? -1 : 1);
			break;
		case 'L':
			res += 50;
			break;
		case 'C':
			res += 100 * (res >= 500 ? -1 : 1);
			break;
		case 'D':
			res += 500;
			break;
		case 'M':
			res += 1000;
			break;
		}
		len--;
	}
	return res;

}
int main()
{
	char* s = "LVIII";
	int sum = romanToInt(s);
	printf("%d", sum);
	return 0;
}